//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by FernFlower decompiler)
//

package com.example.mapper;

import com.example.entity.Clubmember;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

public interface ClubmemberMapper {

    List<Clubmember> selectAll(Clubmember clubmember);

    @Select({"select * from club_member where id = #{id}"})
    Clubmember selectById(Integer id);

    @Select("select * from club_member where president_id = #{presidentId}")
    Clubmember selectBypresidentId(Integer presidentId);

    @Insert({"insert into club_member (club_id,student_id,president_id) values (#{clubId},#{studentId},#{presidentId})"})
    int insert(Clubmember clubmember);

    @Update({"update club_member set role = #{role} where id=#{id}"})
    int updateById(Clubmember clubmember);

    @Delete({"delete from club_member where id = #{id}"})
    int deleteById(Integer id);

    @Select({"<script>",
            "SELECT cm.*, c.name as clubName, s.name as studentName, p.name as presidentName FROM club_member cm ",
            "LEFT JOIN club c ON cm.club_id = c.id ",
            "LEFT JOIN student s ON cm.student_id = s.id ",
            "LEFT JOIN president p ON c.president_id = p.id ",
            "<where>",
            "<if test='clubId != null'> AND cm.club_id = #{clubId} </if>",
            "<if test='clubName != null and clubName != &quot;&quot;'> AND c.name like concat('%', #{clubName}, '%') </if>",
            "<if test='studentName != null and studentName != &quot;&quot;'> AND s.name like concat('%', #{studentName}, '%') </if>",
            "<if test='presidentId != null'> AND c.president_id = #{presidentId} </if>",
            "</where>",
            "order by cm.id desc",
            "</script>"})
    List<Clubmember> selectPage(Clubmember clubmember);


}
